#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=1000000, mods=998244353;

ll qpower(ll a, ll n) {
    ll s=1;
    for (; n; n/=2) {
        if (n&1) s=s*a%mods;
        a=a*a%mods;
    }
    return s;
}

int main() {
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);

    static ll p[maxn+1], f[maxn+1];
    int n;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        ll x, y;
        scanf("%lld %lld", &x, &y);
        p[i] = x*qpower(y, mods-2)%mods;
    }

    f[0] = qpower(p[0], mods-2);
    for (int i=1; i<n; i++) f[i] = ((mods+1-p[i])*f[i-1]%mods+1)%mods*qpower(p[i], mods-2)%mods;
    ll ans=0;
    for (int i=0; i<n; i++) ans=(ans+f[i])%mods;

    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
